<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
  // 权限控制
  public function _initialize(){
       $paths = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
      if(in_array($paths, C('AUTH_PATHS'))){
            if(!isset($_SESSION['id'])){
                $this->error('请先登录',U('home/login/index'));
            }
        }
  }
	// 人气榜
   public function getTopView(){
      $sql="select * from question order  by view_num desc limit 10 ";
      $hotView=M()->query($sql);
      $this->assign('hotView',$hotView);
   }
   // 热议榜
    public function getTopAnswer()
    {
    	$sql = "select * from question order by answer_num desc limit 10 ";

    	$hotAnswer = M()->query($sql);

    	$this->assign('hotAnswer',$hotAnswer);
    }
    // 自增
       public function autoAdd($table,$filed,$num,$id){

    	$sql = "update ".$table." set " .$filed ."=".$filed.$num ." where id='{$id}'";
      
    	M()->execute($sql);
     }
     // 活跃用户榜
  public function getTopUser()
    {
    	$sql = "select * from user order by answer_num desc limit 8";

    	$hotUser = M()->query($sql);

    	$this->assign('hotUser',$hotUser);
    }
   
}